package com.powernode.cudops;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ResourceBundle;

/**
 * @Author Arrebol
 * @Date 2024/7/31 21:56
 * @Project jdbc
 * @Description：
 * 通过获取.properties配置文件中的相关信息连接到数据库（动态配置）
 */
public class JdbcTest3 {
    public static void main(String[] args) {
        //获取配置文件中连接数据库的相关信息
        ResourceBundle bundle=ResourceBundle.getBundle("jdbc");
        String driver = bundle.getString("driver");
        String url = bundle.getString("url");
        String user = bundle.getString("user");
        String password = bundle.getString("password");
        Connection conn=null;
        try {
            Class.forName(driver);
            conn= DriverManager.getConnection(url,user,password);
            System.out.println(conn);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
